<%@ page language="java"
	import="java.util.*,sns.app.nhwc.*,sns.websocketservlet.*"
	pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>你画我猜</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">

		<link href="../../css/nhwcroom.css" rel="stylesheet" type="text/css">

	</head>

	<body>
		<div class="sys-pic" id="head-pic"></div>
		<!-- 定义页面上方浮动栏 -->
		<div id="head-bar">
			<div id="bar-wrap">
				<a href="../../gotoMain.action">
					<div class="sys-pic" id="logo"></div> </a>
				<!-- 使用clear属性清理浮动，下同 -->
				<div class="clear"></div>
			</div>
		</div>
		<div class="wrapper">
			<div class="head" id="gametitle">
				<h2>
					你画我猜
				</h2>
			</div>
			<div class="head" style="color: red;">
				<h3>
					<s:property value="errormsg" />
				</h3>
			</div>
			<div class="head">
				<h3>
					<a href="gotoNHWC.action">快速开始</a>
				</h3>
			</div>
			<table>
				<%
					// get games
					NHWCGame game = null;
					ArrayList<NHWCMessageInbound> connections;
					String status;
					int rows = 10;
					int columns = 5;
					int roomid;
					for (int i = 0; i < rows; i++) {
				%>
				<tr>
					<%
						for (int j = 0; j < columns; j++) {
								roomid = i * columns + j + 1;
								game = NHWCWebSocketServlet.getGameById(roomid);
								if (game == null) {
									connections = new ArrayList<NHWCMessageInbound>();
								} else {
									connections = game.getConnections();
								}
								if (game == null
										|| game.getGameState() == NHWCGame.GAME_WAITING) {
									status = "等待加入";
								} else {
									status = "游戏进行中";
								}
					%>
					<td>
						<div class="roomInfo">
							<a class="roomNum" href="gotoNHWC.action?roomid=<%=roomid%>"><%=roomid%></a>
							<div class="roomStatus"><%=status%></div>
						</div>
						<%
							int cnt = 0;
									for (NHWCMessageInbound c : connections) {
										cnt++;
						%>
						<div class="roomPlayer">
							<a href="../../gotoMain.action?userId=<%=c.getIduser()%>"><%=c.getNickname()%></a>
						</div>
						<%
							}
									while (cnt < NHWCGame.PLAYER_MAX) {
										cnt++;
						%>
						<div class="roomPlayer">
							空闲
						</div>
						<%
							}
						%>
					</td>
					<!-- any necessary details of the specific game -->

					<%
						}
					%>
				</tr>
				<%
					}
				%>
			</table>
		</div>
	</body>
</html>
